package com.telecom.restaurant.domin;

import com.telecom.restaurant.constant.DefaultConstant;

/**
 * Created by qiqi on 2019/12/3.
 */
public class PaginationParam {

    protected boolean pagination = true;

    protected int pageSize;

    protected int pageNo;

    public PaginationParam() {
        pageSize = DefaultConstant.DEFAULT_PAGE_SIZE;
        pageNo = DefaultConstant.DEFAULT_PAGE_NO;
    }

    public PaginationParam(Integer pageNo, Integer pageSize){
        setPageNo(pageNo);
        setPageSize(pageSize);
    }


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if(pageSize == null || pageSize <= 0){
            pageSize = DefaultConstant.DEFAULT_PAGE_SIZE;
        }
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        if(pageNo == null || pageNo <= 0){
            pageNo = DefaultConstant.DEFAULT_PAGE_NO;
        }
        this.pageNo = pageNo;
    }

    public int getOffset(){
        return (pageNo - 1) * pageSize;
    }

    public int getLimit(){
        return pageSize;
    }

    public boolean isPagination() {
        return pagination;
    }

    public void setPagination(boolean pagination) {
        this.pagination = pagination;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
}
